package com.zzccyy.jpdemo;

import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentPagerAdapter;

import com.zzccyy.jpdemo.fragment.Fragment1;
import com.zzccyy.jpdemo.fragment.Fragment2;
import com.zzccyy.jpdemo.fragment.Fragment3;
import com.zzccyy.jpdemo.fragment.Fragment4;

public class ViewPagerAdapter extends FragmentPagerAdapter {
    // 页面数量
    private static final int PAGE_COUNT = 4;

    public ViewPagerAdapter(FragmentManager fm) {
        super(fm, BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT);
    }

    // 根据位置返回对应Fragment
    @Override
    public Fragment getItem(int position) {
        switch (position) {
            case 0: return new Fragment1();
            case 1: return new Fragment2();
            case 2: return new Fragment3();
            case 3: return new Fragment4();
            default: return new Fragment1();
        }
    }

    // 返回页面总数
    @Override
    public int getCount() {
        return PAGE_COUNT;
    }
}